﻿#region
/*******************************************************************************
** File Name:		    FoodInfoService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class FoodInfoService : IFoodInfoService
    {
		 IFoodInfo foodInfo = new FoodInfoRepository();
		 
		 #region  Auto Generation
		 

		public void UpdateByFoodInfoID (FoodInfoModel model)
		{
			EFoodInfo entity = ConvertModelToEntity(model);

            foodInfo.UpdateByFoodInfoID(entity);

		}

		public void DeleteByFoodInfoID (System.Int64 foodInfoID)
		{
		
            foodInfo.DeleteByFoodInfoID(foodInfoID);

		}
		 
        public FoodInfoModel GetByFoodInfoID (System.Int64 foodInfoID)
        {
        
			EFoodInfo entity = foodInfo.GetByFoodInfoID(foodInfoID);
			
            FoodInfoModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<FoodInfoModel> GetAll ()
		{
			IList<EFoodInfo> entity = foodInfo.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<FoodInfoModel> list = new List<FoodInfoModel>();

            foreach (var item in entity)
            {
                FoodInfoModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private FoodInfoModel ConvertEntityToModel(EFoodInfo entity)
		{
			if (entity == null)
            {
                return null;
            }
			FoodInfoModel model = new FoodInfoModel();
                        model.FoodInfoID = entity.FoodInfoID;
                        model.Name = entity.Name;
                        model.Price = entity.Price;
                        model.UnitID = entity.UnitID;
                        model.FoodDepartmentID = entity.FoodDepartmentID;
                        model.FoodCategoryID = entity.FoodCategoryID;
                        model.FoodAttributeID = entity.FoodAttributeID;
                        model.FoodTasteID = entity.FoodTasteID;
                        model.FoodPracticeID = entity.FoodPracticeID;
                        model.ImagePath = entity.ImagePath;
                        model.Remark = entity.Remark;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        return model;
		}
		
		private EFoodInfo ConvertModelToEntity(FoodInfoModel model)
		{
			if (model == null)
            {
                return null;
            }
			EFoodInfo entity = new EFoodInfo();
                        entity.FoodInfoID = model.FoodInfoID;
                        entity.Name = model.Name;
                        entity.Price = model.Price;
                        entity.UnitID = model.UnitID;
                        entity.FoodDepartmentID = model.FoodDepartmentID;
                        entity.FoodCategoryID = model.FoodCategoryID;
                        entity.FoodAttributeID = model.FoodAttributeID;
                        entity.FoodTasteID = model.FoodTasteID;
                        entity.FoodPracticeID = model.FoodPracticeID;
                        entity.ImagePath = model.ImagePath;
                        entity.Remark = model.Remark;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        return entity;
		}
		
		
		
		#endregion
    }
}